package net.borlis.sample.horses.core;

/**
 * Created by Alexander on 21.12.2014.
 */
public enum Denominator implements Comparable<Denominator>{
    HUNDRED(100, 5),
    TWENTY(20, 2),
    TEN(10, 2),
    FIVE(5, 2),
    ONE(1, 5);

    private final Integer value;
    private final Integer multiplier;

    Denominator(Integer value, Integer multiplier) {
        this.value = value;
        this.multiplier = multiplier;
    }

    public Integer value() {
        return value;
    }

    public Integer multiplier() {
        return multiplier;
    }

    public Denominator lower() {
        if (this.equals(Denominator.HUNDRED)) {
            return Denominator.TWENTY;
        } else if (this.equals(Denominator.TWENTY)) {
            return Denominator.TEN;
        } else if (this.equals(Denominator.TEN)) {
            return Denominator.FIVE;
        } else if (this.equals(Denominator.FIVE)) {
            return Denominator.ONE;
        } else {
            return Denominator.HUNDRED;
        }
    }

    public Boolean hasLower() {
        if (this.equals(Denominator.ONE)) {
            return false;
        }
        return true;
    }

    public static Denominator byNumber(Integer value) {
        if (value.equals(HUNDRED.value())) {
            return HUNDRED;
        }
        if (value.equals(TWENTY.value())) {
            return TWENTY;
        }
        if (value.equals(TEN.value())) {
            return TEN;
        }
        if (value.equals(FIVE.value())) {
            return FIVE;
        }
        if (value.equals(ONE.value())) {
            return ONE;
        }
        throw new IllegalArgumentException(" There is no denominator like " + value + " in system");
    }
}
